<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        .box{
            width: 500px;
            margin: 100px auto;
        }
        #box div{
            border: 1px solid;
            width:500px;
            height:300px;
            text-align: center;
            line-height: 300px;
            color: black;
            display:none;
        }
        input{
            padding: 10px 20px;
        }
        .active{
            background:red;
            color:white;
        }

    </style>
</head>
<body>
<div id="box" class="box">
    <input class="active" type="button" value="第一名">
    <input type="button" value="第二名">
    <input type="button" value="第三名">
    <div style="display:block">我是第一页</div>
    <div>我是第二页</div>
    <div>我是第三页</div>
</div>
</body>
<script>
    window.onload = function(){
        var obj = new Tab("box");
        obj.init();
    }
    function Tab(id){
        this.oParent = document.getElementById(id);
        this.aInput = this.oParent.getElementsByTagName("input");
        this.aDiv = this.oParent.getElementsByTagName("div");
    }
    Tab.prototype.init = function(){
        var This = this;
        for(var i=0; i<this.aInput.length;i++){
            this.aInput[i].index = i;
            this.aInput[i].onclick=function(){
                This.change(this);
            }
        }
    };
    Tab.prototype.change = function(obj){
        for(var i=0; i<this.aInput.length;i++){
            this.aInput[i].className="";
            this.aDiv[i].style.display="none";
        }
        obj.className="active";
        this.aDiv[obj.index].style.display="block";
    }
</script>
</html>
